<template>
  <div class="list-table">
    <el-form ref="queryForm" :model="queryParams" :inline="true" style="position: unset;height: unset;">
      <el-form-item :label="$t('违约债券名称')" prop="name">
        <el-input
          v-model="queryParams.name"
          :placeholder="$t('违约债券名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-if="!btnHide && processBtn"
          v-hasPermi="['fund:monitor:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="fundDefaultBondList" border tooltip-effect="darkTable">
      <!--      <el-table-column type="index" align="center" show-overflow-tooltip width="50" fixed>-->
      <!--        <template slot-scope="scope">-->
      <!--          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column :label="$t('序号')" align="center" prop="num" min-width="50" fixed />
      <el-table-column :label="$t('违约债券名称')" align="center" prop="name" width="200" fixed show-overflow-tooltip>
        <template slot-scope="scope">
          <el-link class="link-a" type="primary" @click="updateHandle(scope.row)">{{ scope.row.name }}</el-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('违约债券编码')" align="center" prop="number" width="200" />
      <el-table-column :label="$t('违约债券市值(元)')" align="center" prop="marketValue" width="180">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.marketValue) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('违约债券估值依据')" align="center" prop="valuationBasis" width="200" show-overflow-tooltip />
      <el-table-column :label="$t('违约债券成本(元)')" align="center" prop="cost" width="180">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.cost) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('违约债券负面情况类别')" align="center" prop="negative" width="200" show-overflow-tooltip />
      <el-table-column :label="$t('违约债券发行日期')" align="center" prop="issuedDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.issuedDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('违约债券到期时间')" align="center" prop="expireDate" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.expireDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('债券首次发生违约时间')" align="center" prop="defaultDate" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.defaultDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('违约债券面值(元)')" align="center" prop="faceValue" width="180">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.faceValue) }}</span>
        </template>
      </el-table-column>
      <el-table-column v-if="processBtn" :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            v-if="!btnHide"
            v-hasPermi="['fund:monitor:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-if="!btnHide"
            v-hasPermi="['fund:monitor:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改持有违约债券信息对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <fundDefaultBondForm ref="fundDefaultBondForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listFundDefaultBond, delFundDefaultBond, exportFundDefaultBond } from '@/api/fund/operation/fundDefaultBond'
import fundDefaultBondForm from './fundDefaultBondForm.vue'
export default {
    components: {
        fundDefaultBondForm
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 持有违约债券信息表格数据
          fundDefaultBondList: [],
          // 弹出层标题
          title: '持有违约债券信息',
          // 是否显示弹出层
          formOpen: false,
          // 查询参数
          queryParams: {
              monitorId: undefined,
              name: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {},
          processBtn: false,
          btnHide: false
      }
  },
  created() {
      this.getList()
  },
  methods: {
    init(data) {
      this.processBtn = data.processBtn
      this.queryParams.monitorId = data.id
      this.btnHide = data.btnHide
      this.getList()
    },
    /** 查询持有违约债券信息列表 */
    getList() {
        this.loading = true
        listFundDefaultBond(this.queryParams).then(response => {
            this.fundDefaultBondList = response.rows
            this.total = response.total
            this.loading = false
        })
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,

            monitorId: undefined,

            name: undefined,

            number: undefined,

            marketValue: undefined,

            valuationBasis: undefined,

            cost: undefined,

            negative: undefined,

            issuedDate: undefined,

            expireDate: undefined,

            defaultDate: undefined,

            faceValue: undefined,

            principal: undefined,

            interest: undefined,

            type: undefined,

            debtRating: undefined,

            latestDebtRating: undefined,

            situationDesc: undefined,

            cityInvestBond: undefined,

            issuedSubjectName: undefined,

            socialCreditCode: undefined,

            enterpriseTypeFirst: undefined,

            enterpriseTypeSecond: undefined,

            area: undefined,

            industry: undefined,

            subjectRating: undefined,

            remake: undefined

        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.queryParams.processBtn = this.processBtn
            this.queryParams.total = this.total
            this.$refs.fundDefaultBondForm.init(this.queryParams)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            row.processBtn = this.processBtn
            row.btnHide = this.btnHide
            this.$refs.fundDefaultBondForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delFundDefaultBond(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
        const queryParams = this.queryParams
        this.$confirm(this.$t('是否确认导出数据项?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return exportFundDefaultBond(queryParams)
        }).then(response => {
            this.download(response.msg)
        }).catch(function() {
        })
    }
  }
}
</script>
